package com.yunfeng.supercall.activity;

import java.util.Collections;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.ly.quickdev.library.utils.JsonUtils;
import com.yunfeng.supercall.R;
import com.yunfeng.supercall.bean.ContactsBaseBean;
import com.yunfeng.supercall.bean.MyCircleBean;
import com.yunfeng.supercall.httputils.MyAjaxCallBack;

/**
 * 附近的圈子
 * 
 * @author 洋
 * 
 */
public class NearByCircleListActivity extends
		BaseStickyHeaderListActivity<MyCircleBean> {

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		startActivity(new Intent(this, MyCircleDetailActivity.class).putExtra(
				KEY_DATA, mList.get(position)));
	}

	@Override
	public void loadData() {
		// TODO Auto-generated method stub
		JSONObject json = getBaseParams(getActivity());
		setTitleBar(R.string.circle_nearby);
		try {
			json.put(KEY_PAGE_NUM, 0);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		mHttpClient.post(FUNCTION_GET_CIRCLE_NEAR_BY, json,
				new MyAjaxCallBack() {

					@Override
					public void onReceiveError(String msg, String errorCode) {
						// TODO Auto-generated method stub

					}

					@Override
					public void onReceiveData(String data, String msg) {
						// TODO Auto-generated method stub
						mList = JsonUtils.parseList(data, MyCircleBean.class);
						Collections.sort(mList);
						setListAdapter();
					}
				});
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			convertView = getLayoutInflater().inflate(
					R.layout.list_item_system_friends, null);
		}
		ContactsBaseBean.setupSingleLineContactsView(convertView,
				mList.get(position));
		return convertView;
	}

}
